package com.jy.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jy.pojo.User;
import com.jy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("login")
    public User login(@RequestBody User user) {
        LambdaQueryWrapper<User> qw = new LambdaQueryWrapper<>();
        qw.eq(User::getUsername, user.getUsername());
        qw.eq(User::getPassword, user.getPassword());
        return userService.getOne(qw);
    }

    @RequestMapping("checkUsername")
    public String checkUsername(String username) {
        return userService.checkUsername(username);
    }

    @RequestMapping("register")
    public String register(@RequestBody User user) {
        return userService.register(user);
    }

}
